package com.jsp.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;





public class DBUtil {
	private static String URL;
	private static String USER;
	private static String PASSEORD;
	private static String DRIVER;
	private static ResourceBundle config = ResourceBundle.getBundle("com.jsp.util.db-config");
	static{
		URL = config.getString("jdbc.url");
		USER = config.getString("jdbc.user");
		PASSEORD = config.getString("jdbc.password");
		DRIVER = config.getString("jdbc.driver");
		try {
			Class.forName(DRIVER);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	public static Connection getConnection(){
		Connection con = null;
		try {
			con = DriverManager.getConnection(URL, USER, PASSEORD);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return con;
	}

	
	public static void closeConn(ResultSet rs,PreparedStatement pstmt,Connection con){
		if(rs!=null){
			try {
				rs.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if(pstmt!=null){
				try {
					pstmt.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				if(con!=null){
					try {
						con.close();
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}		
     }
}